#include <multimedia/player_framework/native_avcapability.h>
#include <string>
#include "napi/native_api.h"

static napi_value CheckIsSupport(napi_env env, napi_callback_info info) {
    size_t argc = 2;
    napi_value args[2] = {nullptr};

    napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);

    int32_t decoderType;
    napi_get_value_int32(env, args[0], &decoderType);

    char videoCodecMime[20] = {0};
    size_t videoCodecMimeStrlen;
    size_t len = 20;
    napi_get_value_string_utf8(env, args[1], videoCodecMime, len, &videoCodecMimeStrlen);

    OH_AVCapability *capability =
        OH_AVCodec_GetCapabilityByCategory(videoCodecMime, false, decoderType ? SOFTWARE : HARDWARE);
    int32_t result = capability ? 1 : 0;

    napi_value res;
    napi_create_int32(env, result, &res);
    return res;
}

EXTERN_C_START
static napi_value Init(napi_env env, napi_value exports) {
    napi_property_descriptor desc[] = {
        {"checkIsSupport", nullptr, CheckIsSupport, nullptr, nullptr, nullptr, napi_default, nullptr}};
    napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc);
    return exports;
}
EXTERN_C_END

static napi_module demoModule = {
    .nm_version = 1,
    .nm_flags = 0,
    .nm_filename = nullptr,
    .nm_register_func = Init,
    .nm_modname = "entry",
    .nm_priv = ((void *)0),
    .reserved = {0},
};

extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); }
